/*
 * File:   main.cpp
 * Author: Kreyl
 *
 * Created on May 27, 2011, 6:37 PM
 */

#include "kl_lib.h"
#include "led.h"

#include "usbd_dfu_core.h"
#include "usbd_usr.h"
#include "usbd_desc.h"
#include "usb_conf.h"

// Prototypes
void GeneralInit(void);
void LedInit(void);

// ==== LED's ====
LedSmooth_t PwrLed;

void LedTask(void);

__ALIGN_BEGIN USB_OTG_CORE_HANDLE    USB_OTG_dev __ALIGN_END ;


pFunction Jump_To_Application;
uint32_t JumpAddress;

// ============================ Implementation ================================
int main(void) {
    GeneralInit();
    // Led On
    PwrLed.SetSmoothly(40);


//    USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &DFU_cb, &USR_cb);
    // ==== Main cycle ====
    klPinSetup(GPIOA, 15, pmOutPushPull, ps50MHz);
    klPinSet(GPIOA, 15);
    while(1) {
        LedTask();
    } // while(1)
}

void GeneralInit(void) {
    // Disable JTAG
    klJtagDisable();
    //System Clock
    SystemCoreClockUpdate();
    // Init peripheral
    Delay.Init();
    // Led's Init
    LedInit();
    // Init USART1 as debug uart PA9 - TX
    CmdUnit.Init(57600);

    CmdUnit.Printf("\rUsbBoot\r");
}

void LedInit(){
    PwrLed.Init(GPIOB, 0, TIM3, 1000, 0, 3, false);
}
void LedTask() {
    PwrLed.Task();
}
